<template>
  <div>
    <van-nav-bar
      title="评论"
      left-arrow
      @click-left="$router.back()"
    />
    <div class="main">
      <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad">
          <van-cell v-for="(item,i) in commentList" :key="i">
            <template #title>
              <div class="wrap">
                <div class="img_wrap">
                  <img :src="item.user.avatarUrl" alt="">
                </div>
                <div class="content_wrap">
                  <div class="header_wrap">
                    <div class="info_wrap">
                      <span>{{item.user.nickname}}</span>
                      <p>{{item.timeStr}}</p>
                    </div>
                    <div class="agree_with">
                      <span class="likearea">
                        <span>{{item.likedCount}}</span>
                        <van-icon name="good-job-o" size="14px" />
                      </span>
                    </div>
                  </div>
                  <div class="footer_wrap">
                    <span>{{item.content}}</span>
                  </div>
                </div>
              </div>
            </template>
          </van-cell>
        </van-list>
      </van-pull-refresh>
    </div>

  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'Comment-index',
  data () {
    return {
      isLoading: false, // 上拉刷新
      loading: false, // 控制到底下拉刷新
      finished: false // 数据没有了
    }
  },
  computed: {
    ...mapState(['commentList', 'limit', 'page'])
  },
  methods: {
    onRefresh () { // 下拉刷新
      this.$store.dispatch('musicComment', this.$route.query.id, this.limit, (this.page - 1) * this.limit)
      this.$store.commit('REST_DATA')
      setTimeout(() => {
        this.isLoading = false
      }, 100)
    },
    onLoad () { // 上拉请求数据
      this.$store.dispatch('musicComment', this.$route.query.id, this.limit, (this.page - 1) * this.limit)
      this.loading = false
      this.finished = false
      this.$store.commit('PAGE_UP') // 让页数加1
    }
  }
}
</script>

<style scoped lang="less">
.wrap{
  padding-top: 10px;
  display: flex;
  .img_wrap{
    height: 35px;
    margin: 0 10px 0 0;
    flex: none;
    img{
      display: block;
      border-radius: 50%;
      width: 30px;
      height: 30px;
    }
  }
  .content_wrap{
    padding-right: 0;
    padding-bottom: 16px;
    padding-left: 0;
    flex: auto;
    .header_wrap{
      display: flex;
      justify-content: space-between;
      flex-direction: row;
      .info_wrap{
        -webkit-box-flex: 1;
        span{
          max-width: 100%;
          display: -webkit-inline-box;
          display: -webkit-inline-flex;
          display: inline-flex;
          -webkit-box-align: center;
          -webkit-align-items: center;
          align-items: center;
        }
        p{
          font-size: 9px;
          color: #999;
        }
      }
      .agree_with{
        width: 65px;
        height: 22px;
        line-height: 22px;
        font-size: 11px;
        color: #999;
        -webkit-flex: none;
        -webkit-box-flex: 0;
        flex: none;
        text-align: right;
        .likearea{
          display: inline-block;
          min-width: 30px;
          padding-left: 5px;
          span{
            vertical-align: middle;
          }
          /deep/ .van-icon-good-job-o{
            display: inline-block;
            width: 14px;
            height: 14px;
            margin-left: 6px;
            line-height: 0;
            vertical-align: sub;
            cursor: pointer;
          }
        }
      }
    }
    .footer_wrap{
      position: relative;
      color: #333;
      font-size: 15px;
      line-height: 22px;
      margin-top: 5px;
      span{
        vertical-align: middle;
      }
    }
  }
}
</style>
